// pages/finished/finished.js
const app = getApp()
import api from '../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderDetailInfo: {},
    card: {},
    imgUrl: ''
  },
  // 准考证信息
  getPermit() {
    let obj = {}
    obj.order_identifier = this.data.orderDetailInfo.order_identifier
    console.log(obj.order_identifier)
    api.POST('/applet/exam_order/checkExamPermit', obj, res => {
      // 准考证
      console.log(res.data)
      this.setData({
        card: res.data
      })
    })

    api.POST('/applet/ContactService/detail', {}, res => {
      console.log(res.data.exam_card_url)
      this.setData({
        imgUrl: res.data.exam_card_url
      })
    })
  },

  // 复制考点
  copyVenues() {
    console.log(this.data.orderDetailInfo)
    let info = this.data.orderDetailInfo
    let venues = info.province_name + (info.city_name ? info.city_name : '') + (info.area_name ? info.area_name : '')

    wx.setClipboardData({
      data: venues,
      success() {
        wx.getClipboardData({
          success(res) {
            console.log(res.data)
          }
        })
      }
    })
  },
  
  // 查看成绩
  goToCheckGrade(e) {
    let grade = e.currentTarget.dataset.exam_result
    console.log(grade)
    let exam_order_id = e.currentTarget.dataset.exam_order_id
    console.log(exam_order_id)
    
    if (grade == '0.00') {
      wx.showToast({
        title: '暂无考试成绩',
        icon: 'loading'
      })
      return
    } else {
      wx.navigateTo({
        url: '/pages/grade/grade?exam_order_id=' + exam_order_id,
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    api.POST('/applet/exam_order/detail', {
      exam_order_id: options.oid
    }, res => {
      console.log(res)
      console.log(res.data.exam_status, res.data.status)
      this.setData({
        orderDetailInfo: res.data
      })
      console.log(res.data)
    })

    this.getPermit()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})